#include <stdio.h>
#include <string.h>
#include "ifetcher.h"
#include "dalvik-opcode.h"




void CFetcherBase::set_fetch_address(unsigned int _ip_)
{

	//
	// save pointer
	//

	 ip = _ip_;
 

}

//
//  return
//        0: illegal instruction
//        1: success
//        2: end
//
int CFetcherBase::fetch(PINSN_INFO p_insn )
{
	unsigned char *code;

	unsigned int len;


	//
	// no matter of the result, fill fetch ip so that caller knows about it.
	//
	p_insn->ip=ip;

	//
	// end of insn stream or mmu fetch fault
	//
	if (!bytes ||!buffer) 
		return FETCH_EOF; // no data



	
	code=buffer;



	len = pre_decode(	code,p_insn);
	
	if (len==0) 
		return FETCH_UD;
	
	if (bytes<len) 
		return FETCH_EOF;

	ip +=len;
	buffer+=len;
	bytes-=len;

	return FETCH_SUCCESS;

}



unsigned int CFetcherBase::decode_length(unsigned char  *code)
{


	return 0;
}